// pages/mine/mine.js
var api = require("../../api.js"),
  r = "",
  app = getApp();
Page({
  /** 页面的初始数据*/
  data: {
    //tabbar
    tabbar: {},
    mineData: {}
  },

  /** 生命周期函数--监听页面加载 */
  onLoad: function(options) {
    app.editTabbar();
    /** 调用是否已授权的方法 */
    //getApp().is_empower();
    r = this;
    setTimeout(function() {
      r.initData();
    }, 500);
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {
    app.editTabbar();
    this.initData();
    wx.showNavigationBarLoading(),
      setTimeout(function() {
          wx.hideNavigationBarLoading(), wx.stopPullDownRefresh();
      }, 1000);
  },
  initData: function() {
    var t = new Object();
    t.openId = getApp().globalData.wxUserInfo.openId;
    wx.request({
      url: api.mine.mine,
      data: t,
      success: function(res) {
        if (res.statusCode == 200 && res.data.code == 200) {
          var n = res.data.data;
          if (n.isBindphone == 1) {
            r.setData({
              phone: true,
              mineData: res.data.data
            })
          } else {
            r.setData({
              phone: false,
              mineData: res.data.data
            })
          }
          wx.setStorageSync('userGrade', n.userGrade);
          console.log(r.data)
        }
      }
    })
  },
  bindTel: function() {
    wx.navigateTo({
      url: "../login/login"
    })
  },
  price: function() {
    wx.navigateTo({
      url: "../price/price"
    })
  },
  /** 对鹿合伙人 */
  parner: function() {
    r.goParner();
  },
  /** 思享智库认证 */
  aut_expert: function(){
    wx.navigateTo({
      url: '../aut_expert/aut_expert'
    })
  },
  /** 企业需求填报 */
  demand_report: function(){
    wx.navigateTo({
      url: '../add_enterprise/add_enterprise'
    })
  },
  /** 思享智库 */
  think_tank: function () {
    /** 判断是否申请正在审核 */
    var t = new Object();
    t.open_id = getApp().globalData.open_id;
    wx.request({
      url: api.mine.is_having_aut,
      data: t,
      success: function (res) {
        /** 已审核通过 */
        if (res.data.code == 200) {
          /** 跳转到列表页 */
        }
        /** 审核中 */
        if (res.data.code == 1005) {
          /** 跳转到认证页面 */
          wx.navigateTo({
            url: '../aut_result/aut_result'
          })
          // wx.showToast({
          //   title: '智库审核',
          //   image: '../../images/auditing_01.png',
          //   duration: 2000
          // })
        }
        /** 未申请 */
        if (res.data.code == 404) {
          /** 跳转到认证页面 */
          wx.navigateTo({
            url: "../think_tank_aut/think_tank_aut"
          })
        }
      }
    })
  },
  vip: function() {
    if (r.data.mineData.isBindphone == 0) {
      wx.showModal({
        title: '提示',
        content: '请先绑定手机号',
        success: function(res) {
          if (res.confirm) {
            wx.navigateTo({
              url: "../login/login"
            })
          } else if (res.cancel) {
            console.log('用户点击取消')
          }
        }
      })
    } else {
      wx.navigateTo({
        url: "../viplevel/viplevel?userGrade=" + r.data.mineData.userGrade
      })
    }
  },
  Coupon: function() {
    wx.navigateTo({
      url: "../coupon/coupon"
    })
  },
  /** 预购 */
  pre_purchase: function() {
    wx.navigateTo({
      url: "../pre_purchase/pre_purchase"
    })
  },
  company: function() {
    console.log(r.data.mineData.isCopartner)
    if (r.data.mineData.userGrade != 0) {
      wx.navigateTo({
        url: "../company/company"
      })

    } else {
      wx.showModal({
        title: '提示',
        content: '请先升级用户',
        success: function(res) {
          if (res.confirm) {
            wx.navigateTo({
              url: "../viplevel/viplevel?userGrade=" + r.data.mineData.userGrade
            })
          } else if (res.cancel) {
            console.log('用户点击取消')
          }
        }
      })
    }
  },


  goParner: function() {
    console.log(r.data.mineData.isCopartner)
    if (r.data.mineData.isCopartner == 2) {
      wx.navigateTo({
        url: '../result/result'
      })
    } else if (r.data.mineData.isCopartner == 0) {
      wx.navigateTo({
        url: '../parner/parner'
      })
    } else {
      wx.navigateTo({
        url: '../firstparner/firstparner'
      })
    }
  },
  /** 文章预览 */
  art_look: function() {
    wx.navigateTo({
      url: '../art_see/art'
    })
  },
  /** 活动预览 */
  act_look: function() {
    wx.navigateTo({
      url: '../act_see/act'
    })
  },
  /** 授权登陆 */
  login: function() {
    wx.showModal({
      title: '提示',
      content: '尚未进行授权，请点击确定跳转到授权页面进行授权。',
      success: function(res) {
        if (res.confirm) {
          wx.navigateTo({
            url: '/pages/welcome/welcome',
          })
        }
      }
    })
  },

})